﻿<script>
  // var html_id = 0;
  // $(document).ready(function(){
      // 获取物品id
      var goods_id = getQueryString('goods_id');
      // console.log(goods_id);
      // 获取页面id
      var html_id = getQueryString('html_id');
      console.log(goods_id);
      // 获取单个物品数据
      sdmg("{\"token\":\""+token+"\", \"view_goods\":{\"goods_id\":"+goods_id+"}}");
      console.log("end");
  // })

// 笨方法获取参数
function getQueryString(name) {
  // 解码
    url = decodeURI(url);
    // console.log(url);
    // 正则表达式
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var i = url.indexOf("?");
    if(i==-1){return;}  
    var r = url.substr(i+1).match(reg);  
    if (r != null) return unescape(r[2]);  
    return null;  
}

// 穿戴 脱下装备按钮
function use(goods_id) {
    // 穿戴函数
    sdmg("{\"token\":\""+token+"\", \"goods_rule\":{\"rule\":\"up_or_down_equip_fun\", \"goods_id\":"+goods_id+"}}");
    // 获取单个物品数据
    sdmg("{\"token\":\""+token+"\", \"view_goods\":{\"goods_id\":"+goods_id+"}}");
}

// 赋值穿戴装备信息
function zb_wear(html_id){
  // 从人物属性页面打开弹窗
  if(html_id == 1){
    // 传输装备数据
    $.get(host + "/backpack", {action:"getBackPack", category:119}, function(ret) {
      console.log(JSON.stringify(ret));
      // 还原初始页面
      $(".sx_con").html("<div class='sx' id='equip_hand_left'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>左手</span></a></div><div class='sx' id='equip_hand_right'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>右手</span></a></div><div class='sx' id='equip_wrist_left'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>左腕</span></a></div><div class='sx' id='equip_wrist_right'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>右腕</span></a></div><div class='sx' id='equip_head'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>帽子</span></a></div><div class='sx' id='equip_necklace'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>项链</span></a></div><div class='sx' id='equip_body_up'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>衣服</span></a></div><div class='sx' id='equip_waist'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>腰带</span></a></div><div class='sx' id='equip_foot'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>鞋子</span></a></div><div class='sx' id='equip_back'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>背部</span></a></div><div class='sx' id='equip_decoration'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>饰品</span></a></div><div class='sx' id='equip_amulet'><a href='javascript:void(0)' value='1'><img src='../images/sx.png'><span>护符</span></a></div>");
      // 装备赋值
      $(ret.goods).each(function(i,key){
          // 判断是否穿戴
          if (key.is_wear == 1){
              // 清空原始内容
              $("#part_" + key.equip_part + " span").html("");
              // 装备颜色
              $("#part_" + key.equip_part).addClass("sx"+key.equip_color);
              // 装备图片
              $("#part_" + key.equip_part + " img").attr("src", "images/sx"+key.equip_image+".png");
          }
      })
    }, "json");
    return;
  }
  // 从背包打开的弹窗
  if(html_id == 2){
      // 重新加载背包
      $.get(host + "/backpack", {action:"getBackPack", category:0}, function(res){
         console.log(JSON.stringify(res));
         var backpack = res.backpack;
         // 类别
         var category = res.category;
         // 物品
         var goods = res.goods;
         // 编码json
         var res_info = escape(JSON.stringify(res));
         // 获取物品的类别
         var desc = $(".flsx").text();
         // 类别为全部
         if(desc == "分类筛选"){
           f_goods_category(-1, res_info);
         }
         // 类别为其他的
         else{
           var index = 0;
           switch(desc){
             case "装备":
               index = 0;
               break;
             case "药品":
               index = 1;
               break;
             case "材料":
               index = 2;
               break;
           }
           f_goods_category(1, res_info, index);
         }
     }, "json");
    return;
  }
}
</script>

<!-- 物品弹窗 -->
<div class="tkbox1_con1">
    <div class="zb"><div class="zb_img"><img src="" alt=""></div><span class="zb_mc"></span></div>
    <div class="star_box"><span class="star"></span></div>
    <div class="zb_txt1">
      <span class='zbtxt1_l'></span>
      <span class="zbtxt1_r">剑·150级</span>
    </div>

    <!-- 附加属性 -->
    <div class="zb_txt2">
      <div class="zb_tit01"><span class="zbtit01_txt">附加属性</span><span class="zbtit01_line"></span></div>
      <p class="goods_attr"></p>
    </div>

    <div class="zb_txt3">
     <p>长剑当向秋水诉，颇觉斗量无痕风。</p>
      <p>秋水无痕剑剑身为血色暗红，呈现出奇异的彩色光泽。相传为剑中之祖昆吾剑的剑柄所炼。</p>
    </div>

    <!-- 事件按钮 -->
    <!-- 穿戴 -->
    <div class="zb_cz goods_up" style="display: none;">
      <a class='but02 zb_up' onclick="">穿戴</a><a class='but02'>镶嵌</a><a class='but02'>洗练</a><a class='but02'>出售</a>
    </div>
    <!-- 脱下 -->
    <div class="zb_cz goods_down" style="display: none;">
      <a class='but02 zb_down' onclick="">脱下</a><a class='but02'>镶嵌</a><a class='but02'>洗练</a><a class='but02'>出售</a>
    </div>

 </div>
<div class='tk_button'><a class='but03' name='gb' onclick="zb_wear(html_id)">关闭</a></div>